package com.jackykeke.opengldemo.renderer;

import android.opengl.GLSurfaceView;

import org.jetbrains.annotations.NotNull;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import static com.jackykeke.opengldemo.renderer.MyNativeRender.SAMPLE_TYPE;

public class MyGLRender implements GLSurfaceView.Renderer {


    private MyNativeRender mNativeRender;

    private int mSampleType;

    public MyGLRender() {
        this.mNativeRender = new MyNativeRender();
    }

    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        mNativeRender.native_OnSurfaceCreated();

    }

    @Override
    public void onSurfaceChanged(GL10 gl, int width, int height) {

        mNativeRender.native_OnSurfaceChanged(width, height);
    }

    @Override
    public void onDrawFrame(GL10 gl) {
        mNativeRender.native_OnDrawFrame();
    }


    public void init() {
        mNativeRender.native_Init();
    }

    public void unInit() {
        mNativeRender.native_UnInit();
    }

    public int getmSampleType() {
        return mSampleType;
    }

    public void setmSampleType(int mSampleType) {
        this.mSampleType = mSampleType;
    }

    public void setTouchLoc(float touchX, float touchY) {
        mNativeRender.native_SetParamsFloat(MyNativeRender.SAMPLE_TYPE_SET_TOUCH_LOC, touchX, touchY);

    }


    public void updateTransformMatrix(float rotateX, float rotateY, float scaleX, float scaleY) {
        mNativeRender.native_UpdateTransformMatrix(rotateX, rotateY, scaleX, scaleY);
    }


    public void setImageData(@NotNull int format, int width, int height, @NotNull byte[] bytes) {
        mNativeRender.native_SetImageData(format, width, height, bytes);
    }

    public void setParamsInt(int paramType, int value0, int value1) {

        if (paramType == SAMPLE_TYPE) {
            mSampleType = value0;
        }
        mNativeRender.native_SetParamsInt(paramType, value0, value1);
    }

}
